package bug;

import bug.dao.hibernate.UserDaoHibernate;
import bug.persistent.*;
import org.hibernate.Query;
import org.hibernate.classic.Session;

import java.util.Iterator;
import java.util.List;

/**
 * User: ion
 * Date: Aug 30, 2008 - 10:54:08 AM
 */

public class Main6 extends BaseMain {

    public static void main(String[] args) {
        new Main6().run();
    }

    public void run() {

        Session s = beginSession();

        List<User> users= userDao.getAll();
        System.out.println(users.size() + " users.");
        for (User user : users) {
            System.out.println(user.getUserProjects().size());
        }

        User u = userDao.getById(1);
        for (UserProject up : u.getUserProjects()) {
            System.out.println(up.getProject().getName());
        }

/*
        String HQL = "from User u join fetch u.userProjects up join fetch up.project p";
        Query q = s.createQuery(HQL);
        List<User> users = q.list();

        for (User user : users) {
            System.out.println(user.getLoginName() + ": " + user.getUserProjects().size());
        }
*/


        endSession();



/*
        beginSession();

        User u2 = userDao.getById(1);
        System.out.println(">>>" + u2.hashCode());
        // System.out.println(u2.getIssues().size());

        System.out.println("-----------------");

        u2 = ((UserDaoHibernate)userDao).merge(u);
        System.out.println(">>>" + u2.hashCode());

        endSession();
*/
    }
}